package Relatives;

import java.io.PrintStream;
import java.util.Scanner;

/**
 * resolve o Relatives
 * 10299 - Relatives
 * @author Jonas Jeske www.inf.ufrgs.br/~jjeske
 * Status: ACCEPTED
 *
 */
public class Main {
	
	public static void main(String[] args){
		Main relatives = new Main();
		relatives.begin();
	}

	private void begin() {
		Scanner entrada = new Scanner(System.in);
		PrintStream saida = new PrintStream(System.out);
		
		long n = entrada.nextLong();
		while(n!=0){
			saida.printf("%d\n", resolve(n));
			n = entrada.nextLong();
		}
	}
/*
 * Sample Input
7
12
0

Output for Sample Input
6
4


 */
	
	/*
	 * implementa a formula de Euler
	 */
	private static long resolve(long i) {
		long resultado;
		long j;
		
		if(i == 1){
			return 0; 
		}
		resultado = i;
        /* Check for divisibility by every prime number below the square root. */
        /* Start with 2. */
		if(i%2 == 0){
			resultado -= resultado/2;
			while(i%2==0){
				i/=2;
			}
		}
		/* Since this doesn't use a list of primes, check every odd number. Ideally, skip past composite numbers.*/
		for (j=3; j*j<=i; j+=2)
		{
			if (i%j==0)
			{
				resultado-=resultado/j;
				while(i%j==0){
					i/=j;
				}
			}
		}
        /* If i>1, then it's the last factor at this point. */
		if (i>1) resultado-=resultado/i;
		
		
		return resultado;
	}
}